{extend name="../../base/view/common/base" /}
<!-- 主体 -->

{block name="body"}
<style>
	.countBan {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		align-content: center;
		justify-content: flex-end;
	}

	.count_item_show {
		display: flex;
		margin: 10px;
		align-content: center;
		align-items: center;
	}
</style>
<form class="layui-form p-4">
	<h3 class="pb-3">功能菜单/节点</h3>
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray-2">供应商<font>*</font>
			</td>
			<td>
				<select name="purveyorId" id="purveyorId" lay-filter="purveyorId" lay-search>
					<option value="">请选择</option>
					{volist name="punList" id="pl"}
					<option value="{$pl.id}" {if isset($detail.purveyorId)&&$detail.purveyorId == $pl.id} selected {/if}>{$pl.name}</option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray">单据日期<font>*</font>
			</td>
			<td>
				<input type="text" name="orderDate" id="orderDate" value="{$detail.orderDate|default=date('Y-m-d')}" lay-verify="required" readonly autocomplete="off" placeholder="请输入"
					   lay-reqText="请输入" class="layui-input">
			</td>


			<td class="layui-td-gray">付款方式<font>*</font>
			</td>
			<td>
				<select name="payType" >
					{foreach ['1'=>'现金','2'=>'银行电汇','3'=>'电子承兑'] as $pkey=>$pt}
					<option value="{$pkey}" {if isset($detail.payType)&&$detail.payType == $pkey} selected {/if}>{$pt}</option>
					{/foreach}
				</select>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">开户行 </td>
			<td>
				<input type="text" readonly disabled class="layui-input" id="kaihuhang" value="{$detail.bank|default=''}">
			</td>
			<td class="layui-td-gray">开户账户 </td>
			<td>
				<input type="text" readonly disabled class="layui-input" id="khzhanghu" value="{$detail.bankCard|default=''}">
			</td>
			<td class="layui-td-gray">销售单位</td>
			<td><select name="saleUnit" lay-search >
				<option value="">销售单位</option>
				{volist name="departList" id="dl" }
				<option title="{$dl.title}"  value="{$dl.id}" {if isset($detail.saleUnit)&&$detail.saleUnit == $dl.id} selected{/if}>{$dl.title}</option>
				{/volist}
			</select></td>
		</tr>
		<tr>
			<td class="layui-td-gray">实际付款时间 </td>
			<td>
				<input type="text" readonly name="payDate" id="payDate" value="{$detail.payDate|default=''}" class="layui-input" lay-verify="required" placeholder="选择时间"  >
			</td>
			<td class="layui-td-gray">备注 </td>
			<td colspan="3">
				<input type="text" name="moRemark"  class="layui-input" value="{$detail.moRemark|default=''}">
			</td>
		</tr>

<!--		<tr>-->
<!--			<td class="layui-td-gray">关联合同<font>*</font>-->
<!--			</td>-->
<!--			<td>-->
<!--				<select name="contractOrder" id="contractOrder" lay-filter="contractOrder">-->
<!--					<option value="">选择供应商</option>-->
<!--				</select>-->
<!--			</td>-->

<!--			</td>-->
<!--			<td class="layui-td-gray">未付金额 </td>-->
<!--			<td>-->
<!--				<input type="text" readonly class="layui-input" id="unPay">-->
<!--			</td>-->
<!--			<td class="layui-td-gray">合同金额 </td>-->
<!--			<td>-->
<!--				<input type="text" readonly name="contactMoney" class="layui-input" id="contactMoney" value="{$detail.contactMoney|default=0}">-->
<!--			</td>-->

<!--		</tr>-->
<!--		<tr>-->
<!--			<td class="layui-td-gray">金额<font>*</font>-->
<!--			</td>-->
<!--			<td>-->
<!--				<input type="text" name="money" value="{$detail.money|default=''}" lay-verify="required" autocomplete="off" placeholder="请输入"-->
<!--					   lay-reqText="请输入" onblur="digitalFiltering(this,2)" class="layui-input">-->
<!--			</td>-->
<!--			<td class="layui-td-gray">打款银行<font>*</font>-->
<!--			<td>-->
<!--				<input type="text" name="payBank" value="{$detail.payBank|default=''}" lay-verify="required" autocomplete="off" placeholder="请输入"-->
<!--					   lay-reqText="请输入" class="layui-input">-->
<!--			</td>-->

<!--		</tr>-->
		<tr>
			<td colspan="6">明细</td>
		</tr>
		<tr><td colspan="6">
			<a href="javascript:" class="layui-btn layui-btn-xs" onclick="addMx()">选择合同</a>
		</td></tr>
<tr>
	<td colspan="6">
		<table class="layui-table tableMany">
			<thead>
			<tr>
				<th>序号</th>
				<th>品牌</th>
				<th>品名</th>
				<th>型号</th>
				<th>订货号</th>
				<th>计量单位</th>
				<th>采购合同</th>
				<th>货商合同</th>
				<th>采购金额</th>
				<th>已到货金额</th>
				<th>已到货未付款金额</th>
				<th>已付款金额</th>
				<th>未付款金额</th>
				<th>本次付款比列</th>
				<th>本次付款金额</th>
				<th>操作</th>
			</tr>
			</thead>
			<tbody id="mxBody">
			{volist name="mxList" id="ml" key="k"}
			 <tr>
				                        <td>
					                            <span class="xuhao">{$k}</span>
					                            <input type="hidden" name="mx[mxid][]" value="{$ml.id}">
					                            <input type="hidden" class="contractId" name="mx[contractId][]" value="{$ml.contractId}">
					                            <input type="hidden" class="contractMxId" name="mx[contractMxId][]" value="{$ml.contractMxId}">
					                            <input type="hidden" class="mdId" name="mx[mdId][]" value="{$ml.mdId}">
					                        </td>
				 <td>{$ml.brand}</td>
				 <td>{$ml.mdName}</td>
				 <td>{$ml.specs}</td>
				 <td>{$ml.buyCode}</td>
				 <td>{$ml.unit}</td>
				                        <td><input type="text" name="mx[contractOrder][]" class="layui-input" value="{$ml.contractOrder}" readonly></td>
				                        <td><input type="text" name="mx[hsContract][]" class="layui-input" value="{$ml.hsContract}" ></td>
				                        <td><input type="text" name="mx[contactMoney][]" class="layui-input contractMoney" value="{$ml.contactMoney}" readonly></td>
				                        <td><input type="text" name="mx[dhMoney][]" class="layui-input" value="{$ml.dhMoney}" readonly></td>
				                        <td><input type="text" name="mx[dhUnpayMoney][]" class="layui-input" value="{$ml.dhUnpayMoney}" readonly></td>
				                        <td><input type="text" name="mx[payedMoney][]" class="layui-input" value="{$ml.payedMoney}" readonly></td>
				                        <td><input type="text" name="mx[unPayMoney][]" class="layui-input" value="{$ml.unPayMoney}" readonly></td>
				                        <td><span class="fkBl">{$ml.fkbl}</span></td>
				                        <td><input type="text" name="mx[money][]" value="{$ml.money}" class="layui-input mxMoney" onblur="getfjBl(this)" lay-verify="required" oninput="digitalFiltering(this,2)"></td>
				                        <td>	{if !isset($detail.status)||$detail.status==1}
											<a href="javascript:" class="layui-btn layui-btn-xs layui-btn-danger" onclick="delMx('{$ml.id}',this)">删除</a>
											{/if}
										</td>
				                    </tr>
			{/volist}
			</tbody>
		</table>
	</td>
</tr>
<tr>
	<td colspan="6">
		<div class="countBan">
			<div class="count_item_show">付款总额：<span id="priceCount">{$countPrice|default=0}</span></div>
		</div>
	</td>
</tr>
	</table>
	{if !$id ||(isset($detail.status)&&$detail.status==1)}
	<table class="layui-table layui-table-form" style="margin-top:12px">
		<tr>
			<td class="layui-td-gray">审批流程<font>*</font></td>
			<td colspan="5">
				<select name="flow_id"  lay-filter="flowtype" lay-reqText="请选择审批流程">
					<option value="">--请选择--</option>
					{volist name="flows" id="vo"}
					<option value="{$vo.id}" title="{$vo.check_type}">{$vo.name}</option>
					{/volist}
				</select>
			</td>
		</tr>
		<tr id="flow_tr">
			<td class="layui-td-gray">审核人<font>*</font></td>
			<td colspan="5">
				<input type="hidden" name="check_admin_ids" value="" readonly><input type="text" name="check_admin_name" value="" autocomplete="off" placeholder="请选择审核人"  lay-reqText="请选择审核人" class="layui-input" readonly>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">抄送人</td>
			<td colspan="5">
				<input type="text" name="copy_names" value="" autocomplete="off" placeholder="请选择审核人" class="layui-input picker-more" readonly><input type="hidden" name="copy_uids" value="" readonly>
			</td>
		</tr>
	</table>
	{else}
	<table class="layui-table layui-table-form mt-4">
		<tr>
			<td class="layui-td-gray-2">审核状态</td>
			<td>{eq name="$detail.check_status" value="0"}<span class="black">待审批</span>{/eq}
				{eq name="$detail.check_status" value="1"}<span class="blue">审批中</span>{/eq}
				{eq name="$detail.check_status" value="2"}<span class="green">已通过</span>{/eq}
				{eq name="$detail.check_status" value="3"}<span class="red">已拒绝</span>{/eq}
				{eq name="$detail.check_status" value="4"}<span class="red">已撤销</span>{/eq}
				{eq name="$detail.check_status" value="5"}<span class="yellow">已通过，并打款</span>{/eq}
			</td>
			<td class="layui-td-gray-2">当前审核人</td>
			<td>{$detail.check_user}</td>
			<td class="layui-td-gray">抄送人</td>
			<td>{$detail.copy_user}</td>
		</tr>
		<tr>
			<td class="layui-td-gray">审批流程</td>
			<td colspan="5">
				<div class="flow-flexbox check-items flow-flex-row" id="flowList">
					<div class="flow-flexbox check-item flow-flex-row">
						<i class="layui-icon layui-icon-add-circle" data-ok=""></i>
						<div class="check-item-name">{$detail.create_user}</div>
						<div class="check-item-status">创建</div>
						<span class="layui-icon layui-icon-right"></span>
					</div>
				</div>
			</td>
		</tr>
		{notempty name="$check_record"}
		<tr>
			<td class="layui-td-gray">审批记录</td>
			<td colspan="5">
				<ul class="layui-timeline flow-record pt-2">
					{volist name="$check_record" id="vo"}
					<li class="layui-timeline-item delete-{$vo.delete_time}">
						<i class="layui-icon layui-timeline-axis">&#xe63f;</i>
						<p style="padding-left:24px">{$vo.check_time_str}<span class="black ml-2">{$vo.name}</span><span class="mx-2 layui-color-{$vo.status}">{$vo.status_str}</span>了此申请。操作意见：<span class="green">{$vo.content}</span></p>
					</li>
					{/volist}
				</ul>
			</td>
		</tr>
		{/notempty}
		{if ( $detail.check_status eq 1) AND ( $is_check_admin eq 1) }
		{eq name="$flows.flow_type" value="0"}
		<tr>
			<td class="layui-td-gray">审批节点 <font>*</font></td>
			<td colspan="5">
				<input type="radio" name="check_node" lay-filter="check_node" value="1" title="审核结束">
				<input type="radio" name="check_node" lay-filter="check_node" value="2" title="下一审批人">
				<div class="layui-inline">
					<input type="text" name="check_admin_name" value="" autocomplete="off" placeholder="请选择下一审批人" lay-verify="required" lay-reqText="请选择下一审批人" class="layui-input picker-one"><input type="hidden" name="check_admin_ids" value="">
				</div>
			</td>
		</tr>
		{/eq}
		<tr>
			<td class="layui-td-gray">审批意见 <font>*</font></td>
			<td colspan="5">
				<textarea name="content" placeholder="请输入审批意见" class="layui-textarea"></textarea>
			</td>
		</tr>
		{/if}
	</table>
	<input type="hidden" name="id" value="{$detail.id}">
	<input type="hidden" name="flow_type" value="{$flows.flow_type|default=0}">
	<input type="hidden" name="check_step_sort" value="{$detail.check_step_sort}">
	<input type="hidden" name="check_status" value="{$detail.check_status}">
	<div id="formBtn" style="padding: 10px 0">
		{eq name="$detail.check_status" value='1'}
		{eq name="$is_check_admin" value='1'}
		<span class="layui-btn layui-btn-normal" data-status="1"><i class="layui-icon layui-icon-ok"></i> 通过</span>
		<span class="layui-btn layui-btn-danger" data-status="2"><i class="layui-icon layui-icon-close"></i> {$flows.flow_type == 5?'回退':'拒绝'}</span>
		{/eq}
		{eq name="$is_create_admin" value='1'}
		<!--        <span class="layui-btn layui-btn-primary" data-status="3"><i class="layui-icon layui-icon-reduce-circle"></i> 撤回</span>-->
		{/eq}
		{/eq}
		{if ( $detail.check_status eq 3) AND ( $is_create_admin eq 1) }
		<!--        <span class="layui-btn layui-btn-primary" data-status="3"><i class="layui-icon layui-icon-reduce-circle"></i> 撤回</span>-->
		{/if}
		{if ( $detail.check_status eq 4) AND ( $is_create_admin eq 1) }
		<!--        <a class="layui-btn" href="/finance/expense/add?id={$detail.id}">重新编辑</a>-->
		{/if}
	</div>
	{/if}

<!--	<div class="py-3">-->
<!--		<input type="hidden" name="id" value="{$id}">-->
<!--		{if !isset($detail.status)||$detail.status==1}-->
<!--		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">保存</button>-->
<!--		<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
<!--		{/if}-->
<!--		{if isset($detail.status)&&$detail.status==1}-->
<!--		<a href="javascript:" class="layui-btn layui-btn-normal" onclick="onSub()">确认</a>-->
<!--		{/if}-->
<!--		{if isset($detail.status)&&$detail.status==2}-->
<!--		<a href="javascript:" class="layui-btn layui-btn-normal" onclick="onCancel()">撤回</a>-->
<!--		{/if}-->
<!--	</div>-->
	<div class="py-3">
		<input type="hidden" name="id" value="{$id}">
		{if !isset($detail.status)||$detail.status==1}
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="onSave">保存</button>
		{/if}
		{if !isset($detail.status)||$detail.status==1}
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">提交审核</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		{/if}
		{if isset($detail.status)&&($detail.status==2||$detail.status==4)}
		<a href="javascript:" class="layui-btn layui-btn-warm" onclick="onCancel()">撤销</a>
		{/if}
	</div>

</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','employeepicker','oaTool'];
	let contractList=[]
	let contractOrder="{$detail.contractOrder|default=''}"
	let punterId="{$detail.purveyorId|default=''}"
	function gouguInit() {
		var form = layui.form,tool=layui.tool,level=0,oaTool = layui.oaTool;
		//审批相关
		form.on('select(flowtype)', function(data){
			var check_type = data.elem[data.elem.selectedIndex].title;
			var formHtml='<td class="layui-td-gray">审核人<font>*</font></td>\
			<td colspan="5">\
				<input type="text" name="check_admin_name" value="" autocomplete="off" placeholder="请选择审核人" lay-verify="required" lay-reqText="请选择审核人" class="layui-input picker-one"><input type="hidden" name="check_admin_ids" value="">\
			</td>';
			if(check_type == 2){
				$('#flow_tr').html(formHtml);
				form.render();
			}
			if(data.value==''){
				return false;
			}
			console.log('checkType',check_type)
			$.ajax({
				url: "/api/index/get_flow_users",
				type:'get',
				data:{id:data.value},
				success: function (e) {
					if (e.code == 0) {
						var flowLi='';
						var flow_data = e.data.flow_data;
						if(e.data.copy_uids && e.data.copy_uids !=''){
							$('[name="copy_names"]').val(e.data.copy_unames);
							$('[name="copy_uids"]').val(e.data.copy_uids.split(','));
						}
						if(check_type == 1 || check_type == 3){
							for(var a=0;a<flow_data.length;a++){
								var userList='',sign_type = '';
								if(check_type == 1){
									if(flow_data[a].flow_type==1){
										userList+= '<li style="padding:3px 0">当前部门负责人</li>';
									}
									else if(flow_data[a].flow_type==2){
										userList+= '<li style="padding:3px 0">上级部门负责人</li>';
									}
									else{
										if(flow_data[a].flow_type==3){
											sign_type= ' <span class="layui-badge layui-bg-blue">或签</span>';
										}
										if(flow_data[a].flow_type==4){
											sign_type= ' <span class="layui-badge layui-bg-blue">会签</span>';
										}
										for(var b=0;b<flow_data[a].user_id_info.length;b++){
											userList+= '<li style="padding:3px 0"><img src="'+flow_data[a].user_id_info[b].thumb+'" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />'+flow_data[a].user_id_info[b].name+'</li>';
										}
									}
								}
								else if(check_type == 3){
									sign_type= ' <span class="layui-badge layui-bg-blue">'+flow_data[a].flow_name+'</span>'
									for(var b=0;b<flow_data[a].user_id_info.length;b++){
										userList+= '<li style="padding:3px 0"><img src="'+flow_data[a].user_id_info[b].thumb+'" style="width:24px; height:24px; border-radius:50%; margin-right:8px;" />'+flow_data[a].user_id_info[b].name+'</li>';
									}
								}
								flowLi+='<li class="layui-timeline-item">\
									<i class="layui-icon layui-timeline-axis">&#xe63f;</i>\
									<div class="layui-timeline-content">\
									  <p class="layui-timeline-title"><strong>第'+(a+1)+'级审批</strong>'+sign_type+'</p>\
									  <ul>'+userList+'</ul>\
									</div>\
								</li>';
							}
							formHtml = '<td class="layui-td-gray">审批流程</td>\
										<td colspan="7">\
											<ul id="flowList" class="layui-timeline">'+flowLi+'</ul>\
										</td>';
							$('#flow_tr').html(formHtml);
						}
					}
				}
			})
		});
		$('#formBtn').on('click','span', function(data){
			let id=$('[name="id"]').val();
			let content=$('[name="content"]').val();
			let check_status=$(this).data('status');
			let status=4;
			let flow_type = $('input[name="flow_type"]').val();
			let check_node=0,check_admin_ids=0;
			if(flow_type == 0 && check_status==1){
				check_node = $('input[name="check_node"]:checked').val();
				check_admin_ids = $('input[name="check_admin_ids"]').val();
				if(!check_node){
					layer.msg('请选择下一审批节点');
					return false;
				}
				if(check_node == 2 && check_admin_ids==''){
					layer.msg('请选择下一审批人');
					return false;
				}
			}
			if(check_status ==1 || check_status==2){
				if(content==''){
					layer.msg('请输入审批意见');
					return false;
				}
				let confirmTips='确定通过该审核？';
				if(check_status==2){
					confirmTips='确定拒绝该审核？';
					status=5;

				}
				layer.confirm(confirmTips, function(index){
					$.ajax({
						url: "/api/index/flow_check",
						type:'post',
						data:{
							id:id,
							type:"{$flowType}",
							check_node:check_node,
							check_admin_ids:check_admin_ids,
							check:check_status,
							content:content
						},
						success: function (e) {
							layer.msg(e.msg);
							if (e.code == 0) {
								tool.sideClose(1000);
							}
						}
					})
					layer.close(index);
				});
			}
			else if(check_status == 3){
				layer.prompt({
					formType: 2,
					title: '请输入撤回理由',
					area: ['500px', '120px'] //自定义文本域宽高
				}, function(value, index, elem){
					if(value==''){
						layer.msg('请输入撤回理由');
						return false;
					}
					$.ajax({
						url: "/api/index/flow_check",
						type:'post',
						data:{
							id:id,
							type:4,
							check:check_status,
							content:value
						},
						success: function (e) {
							layer.msg(e.msg);
							if (e.code == 0) {
								tool.sideClose(1000);
							}
						}
					})
					layer.close(index);
				});
			}
			return false;
		});
		//end 审批相关
		form.on('select(purveyorId)', function(data){
			let val=data.value

			$("#khzhanghu").val('');
			$("#kaihuhang").val('');
			if (val==''){
				layer.msg('请选择供应商');
				return;
			}
			getSupplier(val);
			// getContract(val);
		})

		form.on('select(contractOrder)', function(data){
			let val=data.value
			console.log('aaaaa',val)
			checkContact(val)
		})
		//监听提交
		form.on('submit(webform)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					setTimeout(function(){
						parent.parent.location.reload();
					},1000);									
				}
			}
			tool.post("add", data.field, callback);
			return false;
		});
		//监听保存
		form.on('submit(onSave)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					setTimeout(function(){
						parent.parent.location.reload();
					},1000);
				}
			}
			tool.post("save", data.field, callback);
			return false;
		});
		layui.laydate.render({
			elem:"#orderDate"
		})
		layui.laydate.render({
			elem:"#payDate"
		})

		// getContract(punterId);

	}

	// function getContract(punterId='') {
	// 	contractList=[];
	// 	$("#contactMoney").val('0');
	// 	$("#contractOrder").empty()
	// 	if (!punterId){
	// 		$("#contractOrder").empty()
	// 		layui.form.render();
	// 		return;
	// 	}else {
	//
	// 		let param={
	// 			type:2,
	// 			moType:3,
	// 			punterId:punterId
	// 		};
	// 		httpRequest("{:url('api/getContractList')}",param,function (res) {
	// 			console.log('res',res)
	// 			if (res.code==0){
	// 				let str='<option value="">选择合同</option>';
	// 				let data=res.data;
	// 				contractList=data;
	// 				data.forEach(function (item) {
	// 					let seText=item.orderNum==contractOrder?'selected':'';
	// 					str+='<option value="'+item.orderNum+'" '+seText+'>'+item.orderNum+'</option>'
	// 				})
	// 				$("#contractOrder").append(str)
	// 				layui.form.render();
	// 			}else {
	// 				$("#contractOrder").empty()
	// 				layui.form.render();
	// 			}
	// 	checkContact(contractOrder)
	// 		},false)
	//
	// 	}
	//
	// }

	function checkContact(contractOrder='') {
		let contactMoney=0;
		let unPay=0;
		if (contractOrder==''){
			$("#contactMoney").val(contactMoney);
			$("#unPay").val(unPay);
			return ;
		}

		contractList.forEach(function (item) {
			console.log(item.orderNum==contractOrder)
			if (item.orderNum==contractOrder){
				contactMoney=item.countMoney;
				unPay=item.unPay;
			}
		})
		$("#contactMoney").val(contactMoney);
		$("#unPay").val(unPay);
	}

	function onSub() {
		let id="{$id}";
		if (id==0){
			layer.msg('操作有误');
			return;
		}
		httpRequest("{:url('onSure')}",{id:id},function (res) {
			if (res.code == 0) {
				setTimeout(function () {
					parent.parent.location.reload();
				}, 1000);
			}
		})
	}
	function onCancel(){
		let id="{$id}";
		if (id==0){
			layer.msg('操作有误');
			return;
		}
		httpRequest("{:url('onCancel')}",{id:id},function (res) {
			if (res.code == 0) {
				setTimeout(function () {
					parent.parent.location.reload();
				}, 1000);
			}
		})
	}

	function addMx() {
		punterId=$("#purveyorId").val();
		if (punterId==''||punterId==0){
			layer.msg('请选择供应商');
			return
		}
		let input=document.querySelectorAll('.contractMxId');
		let mxIds=[];
		input.forEach(function (item) {
			mxIds.push(item.value)
		})
		console.log('mxIds',mxIds)
		boxModel("{:url('api/getCgHtMx')}?punterId="+punterId+"&mxIds="+mxIds.join(','),'添加合同')
		return;
	}
let mxIndex='';
	function saveMx(ojb) {
		console.log('saveMx',ojb)
		layer.close(mxIndex);
		var lastListItem = $('.tableMany tr:last');
		let aa = $(lastListItem).find(".xuhao")
		let len = $(aa).text()
		if (!parseInt(len)) {
			len = 0;
		}
		let index = parseInt(len) + 1;
		let str = '';
		for (var i = 0; i < ojb.length; i++) {
			let item = ojb[i];
			let saleContractDetailId=item.id||0;
			let saleContractOrderNum=item.htNum||'';
			str += '      <tr>\n' +
					'                        <td>\n' +
					'                            <span class="xuhao">' + index + '</span>\n' +
					'                            <input type="hidden" name="mx[mxid][]" value="">\n' +
					'                            <input type="hidden" class="contractId" name="mx[contractId][]" value="'+item.orderId+'">\n' +
					'                            <input type="hidden" class="contractMxId" name="mx[contractMxId][]" value="'+saleContractDetailId+'">\n' +
					'                            <input type="hidden" class="mdId" name="mx[mdId][]" value="'+item.mdId+'">\n' +
					'                        </td>\n' +
					'                        <td>'+item.brand+'</td>\n' +
					'                        <td>'+item.mdName+'</td>\n' +
					'                        <td>'+item.specs+'</td>\n' +
					'                        <td>'+item.buyCode+'</td>\n' +
					'                        <td>'+item.unit+'</td>\n' +
					// '                        <td>' + item.bar_code + '</td>\n' +
					'                        <td><input type="text" name="mx[contractOrder][]" class="layui-input" value="'+saleContractOrderNum+'" readonly></td>\n' +
					'                        <td>  <input type="text" name="mx[hsContract][]" class="layui-input" value="" ></td>\n' +
					'                        <td><input type="text" name="mx[contactMoney][]" class="layui-input contractMoney" value="'+item.bjMoney+'" readonly></td>\n' +
					'                        <td><input type="text" name="mx[dhMoney][]" class="layui-input" value="'+item.dhMoney+'" readonly></td>\n' +
					'                        <td><input type="text" name="mx[dhUnpayMoney][]" class="layui-input" value="'+item.dhUnpayMoney+'" readonly></td>\n' +
					'                        <td><input type="text" name="mx[payedMoney][]" class="layui-input" value="'+item.payedMoney+'" readonly></td>\n' +
					'                        <td><input type="text" name="mx[unPayMoney][]" class="layui-input" value="'+item.unPayMoney+'" readonly></td>\n' +
					'                        <td><span class="fkBl">0</span></td>\n' +
					'                        <td><input type="text" name="mx[money][]" value="'+item.unPayMoney+'" class="layui-input mxMoney" onblur="getfjBl(this)" lay-verify="required" oninput="digitalFiltering(this,2)"></td>\n' +
					'                        <td><a href="javascript:" class="layui-btn layui-btn-xs layui-btn-danger" onclick="delMx(\'\',this)">删除</a></td>\n' +
					'                    </tr>';
			index++;
		}
		$("#mxBody").append(str)
		layui.form.render();
		$(".mxMoney").blur();
	}

	function delMx(id = '', e) {
		if (id == '') {
			$(e).parent().parent().remove()
			return;
		}
		$.ajax({
			url: "{:url('removeMx')}",
			type: 'post',
			dataType: 'json',
			data: {id: id},
			success: function (res) {
				if (res.code != 0) {
					layer.msg(res.msg)
				} else {
					$(e).parent().parent().remove()
				}
			},
			error(e) {
				layer.msg('网络错误，请稍后')
			}
		})
	}
	function getfjBl(obj) {
		let parn=$(obj).parent().parent()
		let val=$(obj).val();
		let count=parn.find('.contractMoney').val();
		fjbl=0;
		if (count>0&& val!=''){
			fjbl=parseFloat(val)/parseFloat(count);
			fjbl=fjbl.toFixed(2)
		}
		parn.find('.fkBl').text(fjbl);
		getCountMoney();
	}
	function getCountMoney() {
		let moneys = 0;

		$(".mxMoney").each(function () {
			let thisMoney = $(this).val();
			if (thisMoney == '') {
				thisMoney = 0;
			}
			thisMoney = parseFloat(thisMoney)
			moneys += thisMoney;
		})
		$('#priceCount').text(moneys)
	}
	//获取供应商信息
	function getSupplier(id='') {
		if (id==''||id==0){
			layer.msg('请选择供应商');
			return;
		}
		httpRequest("{:url('api/getPurveyorInfo')}",{id:id},function (res) {
			if (res.code==0){
				let data=res.data;
				$("#khzhanghu").val(data.bankCard);
				$("#kaihuhang").val(data.bank);
			}
		},false)
	}
</script>
{/block}
<!-- /脚本 -->